import { Album } from './Album';
import { Column, Entity, JoinColumn, ManyToMany, ManyToOne, OneToOne, PrimaryGeneratedColumn, Relation } from "typeorm";
import { PhotoMetadata } from "./PhotoMetadata";
import { Author } from "./Author";
import { User } from './User';
@Entity()
export class Photo {
  
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    length: 100
  })
  name: string;

  @Column("text")
  description: string;

  @Column()
  filename: string;

  @Column("double")
  views: number;

  @Column({ name: 'is_published' })
  isPublished: boolean;

  @OneToOne(
    () => PhotoMetadata,
    (photoMetadata) => photoMetadata.photo, {
    cascade: true,
  })
  metadata: Relation<PhotoMetadata>

  @ManyToOne(() => Author, (author) => author.photos)
  @JoinColumn({ name: 'author_id' })
  author: Author

  @ManyToMany(() => Album, (album) => album.photos)
  albums: Album[]

  @ManyToOne(() => User, (user) => user.photos)
  @JoinColumn({ name: 'user_id' })
  user: User
}